package com.example.area.service.impl;

import com.example.area.dao.AreaMapper;
import com.example.area.service.AreaService;
import com.example.entity.Area;
import com.example.result.CommonResult;
import com.example.utils.MyPageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AreaServiceImpl implements AreaService {
    @Autowired
    AreaMapper areaMapper;
    /**
     * 停车场管理-区域全查
     * @param areaName
     * @param
     * @return
     */
    @Override
    public CommonResult getArea(String areaName) {
        return CommonResult.ok(MyPageHelper.getPageResult(areaMapper.getArea(areaName)));
    }

    /**
     * 停车场管理-区域删除
     * @param id
     * @return
     */
    @Override
    public int delArea(Integer id) {
        int i = areaMapper.delArea(id);
        return i;
    }

    /**
     * 停车场管理-区域增改
     * @param area
     * @return
     */
    @Override
    public int saveOrUpdateArea(Area area) {
        int i = 0;
        if(area.getId() == 0){
            area.setCreateTime(new Date());
            area.setUpdateTime(new Date());
            area.setAreaDelFlag(0);
            i = areaMapper.addArea(area);
        }else {
            area.setUpdateTime(new Date());
            i = areaMapper.updateArea(area);
        }
        return i;
    }
}
